package com.aiyige.arouter.Interceptor;

import android.content.Context;
import android.text.TextUtils;

import com.aiyige.arouter.config.ARouterConfig;
import com.aiyige.utils.AccountUtil;
import com.alibaba.android.arouter.facade.Postcard;
import com.alibaba.android.arouter.facade.annotation.Interceptor;
import com.alibaba.android.arouter.facade.callback.InterceptorCallback;
import com.alibaba.android.arouter.facade.template.IInterceptor;
import com.alibaba.android.arouter.launcher.ARouter;


/**
 * Created by zhuyakun on 2017/12/15.
 */
@Interceptor(priority = 2)
public class BindPhoneInterceptor implements IInterceptor {
    @Override
    public void process(Postcard postcard, InterceptorCallback callback) {
        if ((postcard.getExtra() & ARouterConfig.EXTRA_NEED_BINDPHONE) != 0 && TextUtils.isEmpty(AccountUtil.getCurrentUser().getMobile())) {
            callback.onInterrupt(null);
            ARouter.getInstance()
                    .build(ARouterConfig.BindingPhonePage)
                    .navigation();
        } else {
            callback.onContinue(postcard);
        }
    }

    @Override
    public void init(Context context) {

    }
}
